<template>
    <el-dialog :title="roweleInfo.type ? '查看属性信息' : '补充属性信息'" :visible.sync="open" width="50%" append-to-body
        :before-close="closeDelDialog">
        <el-form :inline="true" ref="form" label-width="130px" class="leftMain">
            <el-form-item label="" v-for="(item, index) in infoList" :key="index">
                <span slot="label"><em style="color:red">{{ item.IS_NO_EMPTY == 0 ? "" : " * " }} </em>
                    {{
                        item.FIELD_CAPTION
                    }}
                </span>

                <input_item :item="item" :inputParams="inputParams" @onChangeTap="onChangeTap"
                    :disabledType="roweleInfo.type"></input_item>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="closeDelDialog">取消</el-button>
            <el-button type="primary" @click="submitDetail">确定</el-button>

        </div>
    </el-dialog>
</template>
<script>
import input_item from "@/components/input/index.vue" //不同类型的input 框
import { updateDocument, fbstat, determine } from "@/api/archive/fileCollection/offlinReception.js"
export default {
    props: ["open", "infoList", "inputParams", "roweleInfo"],
    watch: {
        inputParams: {
            handler(navNew) {

                this.inputList = navNew
                console.log(this.inputList, this.roweleInfo)

            }, immediate: true
        }
    },
    components: {
        input_item
    },
    data() {
        return {
            inputList: []
        }
    },
    methods: {
        //获取input 输入框字段
        onChangeTap(data) {
            if (data.val != undefined) {
                this.inputList = data.queryParams;
            } else {
                this.inputList = data;
            }

        },

        //确定
        submitDetail() {
            var that=this;
            if (that.infoList.length > 0) {
                //将数据从新排序为了弹窗提示做准备
                var arr = [];
                for (var i in that.infoList) {
                    if (that.infoList[i].IS_NO_EMPTY != 0) {
                        arr.push(that.infoList[i])
                    }
                }




                console.log(arr,this.inputList,"sdklfjsdklfjkl")
             
                var column = [];
                for (var n in arr) {
                for (var k in this.inputList) {

                    if (arr[n].FIELD_NAME == k) {
                        arr[n].DEFAULT_VALUE = this.inputList[k]
                    }
                }
                if (arr[n].DEFAULT_VALUE == undefined || arr[n].DEFAULT_VALUE == "null") {
                    this.$message({ message: '请输入' + arr[n].FIELD_CAPTION + '!', type: 'warning' })
                    return
                }


                var DEFAULT_VALUE_INPUT = arr[n].DEFAULT_VALUE.toString(); //trim()方法需要转成成String格式
                console.log(arr[n].DEFAULT_VALUE,"skdlfjdklsj")
                var inputValue = DEFAULT_VALUE_INPUT.trim(); // 去除首尾空格

                if (inputValue === '') {
                    this.$message({ message: '输入' + arr[n].FIELD_CAPTION + '不能全部为空!', type: 'warning' })
                    return
                }
            }

            for (var i in this.inputList) {
                column.push({
                    name: i,
                    value: this.inputList[i],
                })
            }

            console.log(column, "---------------电子文件数据")
             
               
               
               
               
                var dataColumn = [];
                var wjMjs = ""
                for (var k in column) {
                    if (column[k].name == "MJ") {
                        wjMjs = column[k].value
                    }
                    for (var n in this.infoList) {
                        if (column[k].name == this.infoList[n].FIELD_NAME) {
                            dataColumn.push(column[k])
                        }
                    }
                }

                fbstat().then(res => {  //false=不是分保，true=是分保 
                    if (res.data) { //分保的情况下进行密级校验
                        determine({
                            daMj: this.roweleInfo["MJ"],
                            wjMjs: [wjMjs]
                        }).then(res => {
                            if (res.msg != "ok") {
                                this.$message({ message: res.msg, type: 'warning' })
                                return
                            } else {
                                updateDocument({
                                    categoryId: this.roweleInfo.categoryId,
                                    column: dataColumn,
                                    docId: this.roweleInfo.row.DOC_ID,
                                }).then(res => {
                                    if (res.code == "200") {
                                        this.$modal.msgSuccess("操作成功");
                                        this.$emit("closeDeleleDocDialog", "yes", { data: this.inputList, docId: this.roweleInfo.row.DOC_ID })
                                    }
                                })
                            }
                        })
                    } else {
                        updateDocument({
                            categoryId: this.roweleInfo.categoryId,
                            column: dataColumn,
                            docId: this.roweleInfo.row.DOC_ID,
                        }).then(res => {
                            if (res.code == "200") {
                                this.$modal.msgSuccess("操作成功");
                                this.$emit("closeDeleleDocDialog", "yes", { data: this.inputList, docId: this.roweleInfo.row.DOC_ID })
                            }
                        })
                    }
                })
                // console.log(dataColumn,"000000000000000000000000000000000000电子文件数据")


            } else {
                this.$message({ message: '暂无信息', type: 'warning' })
            }
        },
        closeDelDialog() {
            this.$emit("closeDeleleDocDialog")
            this.inputList = [];
        }

    }
}
</script>
<style scoped>
::v-deep .el-dialog {
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow: auto;
}
</style>